//
//  MySuggestionBackViewController.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/9/25.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "MySuggestionBackViewController.h"
#import "PlaceholderTextView.h"
@interface MySuggestionBackViewController ()<UITextViewDelegate>

@property(nonatomic,strong)PlaceholderTextView *textView;
@property(nonatomic,strong)UILabel *stirngLenghLabel;
@end

@implementation MySuggestionBackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createNavagationBackBtn];
    self.title = @"意见反馈";
    [self createUI];
}

-(void)createNavagationBackBtn{
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 6, 67, 23);
    UIImageView *backImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navigator_btn_back"]];
    backImg.frame = CGRectMake(-10, 0, 22, 22);
    [backBtn addSubview:backImg];
    UILabel *backText = [[UILabel alloc] initWithFrame:CGRectMake(12, 0, 65, 22)];
//    backText.text = @"返回";
    backText.font = [UIFont systemFontOfSize:17];
    [backText setBackgroundColor:[UIColor clearColor]];
    [backText setTextColor:[UIColor whiteColor]];
    [backBtn addSubview:backText];
    [backBtn addTarget:self action:@selector(leftBarButtonItemPressed:) forControlEvents:UIControlEventTouchUpInside];
    [backImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backBtn.mas_left).offset(-10);
        make.centerY.equalTo(backBtn.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(22, 22));
    }];
    [backText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backImg.mas_right).offset(2);
        make.centerY.equalTo(backBtn.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(65, 22));
    }];
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    [self.navigationItem setLeftBarButtonItem:leftButton];
}
-(void)leftBarButtonItemPressed:(UIButton *)btn{
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void)createUI{
    [self.view addSubview:self.textView];
    UIButton *subBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:subBtn];
    [subBtn setTitle:@"提交" forState:UIControlStateNormal];
    [subBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    subBtn.backgroundColor = COLOR_HEX(0xffc91f);
    [subBtn addTarget:self action:@selector(RewardSuggestion:) forControlEvents:UIControlEventTouchUpInside];
    [subBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(scaleLeftAndRight(15));
        make.right.equalTo(self.view.mas_right).offset(scaleLeftAndRight(-15));
        make.top.equalTo(self.textView.mas_bottom).offset(60);
        make.height.mas_equalTo(scaleTopAndBottom(45));
    }];
    subBtn.layer.cornerRadius = 22.5f;
    subBtn.layer.masksToBounds = YES;
    
}

-(PlaceholderTextView *)textView{
    if (!_textView) {
        _textView = [[PlaceholderTextView alloc]initWithFrame:CGRectMake(15, 79, WIDTH - 30, 210)];
        _textView.backgroundColor = COLOR_HEX(0xffc91f);
        _textView.delegate = self;
        _textView.font = [UIFont systemFontOfSize:14.f];
        _textView.textColor = [UIColor blackColor];
        _textView.textAlignment = NSTextAlignmentLeft;
        _textView.editable = YES;
        _textView.placeholder = @"您的一小步是我们的一大步呢!您对产品有什么更好的建议统统告诉我们吧!";
    }
    
    return _textView;
}

//把回车键当做退出键盘的响应键  textView退出键盘的操作
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    
    if ([@"\n" isEqualToString:text] == YES)
    {
        [textView resignFirstResponder];
        
        
        return NO;
    }
    
    return YES;
}
-(void)RewardSuggestion:(UIButton *)btn{
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
